///<reference types="cypress" />

import users from '../../fixtures/iworkflow.users.json';

describe('权限测试', () => {
    users.forEach(data => {
        context(`${data.RoleName}账号`, () => {
            let menus;

            before(() => {
                cy.login(data.Account, data.Password);

                cy.get('ul.nav-list>li').then($menus => {
                    menus = $menus;
                });
            });

            after(() => {
                cy.logout();
            });

            it('验证角色拥有的菜单列表', () => {
                // 验证菜单
                cy.validMenus(menus, data.Menus);
            });

            it('验证用户名是否一致', () => {
                cy.get('.user-info').should('contain.text', data.UserName);
            });

            data.Menus.forEach(menu => {
                if (typeof menu == 'object') {
                    let props = Object.getOwnPropertyNames(menu);

                    props.forEach(mainMenu => {
                        let subMenus = menu[mainMenu];

                        subMenus.forEach(subMenu => {
                            it(`访问菜单【${mainMenu}】==>【${subMenu}】`, () => {
                                cy.visitMenu(menus, mainMenu, subMenu);

                                cy.get('#breadcrumbs > ol > li').last().should('contain.text', subMenu);
                            });
                        });
                    });

                } else {
                    it(`访问菜单【${menu}】`, () => {
                        cy.visitMenu(menus, menu);

                        cy.get('#breadcrumbs > ol > li').last().should('have.text', subMenu);
                    });
                }
            });
        });
    });
});